package com.auxgroup.bridge.app.inner.dto;


import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

/**
 * Created by fju on 2017/7/25.
 * 设备信息传输对象 带token，userId，appId
 */
@ApiModel
public class DeviceInfoWithTokenDto implements Serializable {

    @ApiModelProperty(name = "source", value = "来源:0 古北 ,1 机智云", dataType = "string")
    private Integer source;//0 古北 ,1 机智云
    @ApiModelProperty(name = "alias", value = "别名", dataType = "string")
    private String alias;
    @ApiModelProperty(name = "city", value = "城市", dataType = "string")
    private String city;
    @ApiModelProperty(name = "cityCode", value = "城市编码", dataType = "string")
    private String cityCode;
    @ApiModelProperty(name = "dataOne", value = "dataOne", dataType = "string")
    private String dataOne;
    @ApiModelProperty(name = "dataTwo", value = "dataTwo", dataType = "string")
    private String dataTwo;
    @ApiModelProperty(name = "dataThree", value = "dataThree", dataType = "string")
    private String dataThree;
    @ApiModelProperty(name = "deviceKey", value = "设备key", dataType = "string")
    private String deviceKey;
    @ApiModelProperty(name = "deviceLock", value = "设备锁", dataType = "string")
    private String deviceLock;
    @ApiModelProperty(name = "did", value = "设备Did", dataType = "string")
    private String did;
    @ApiModelProperty(name = "isOnline", value = "是否在线", dataType = "boolean",required = true)
    private Boolean isOnline;
    @ApiModelProperty(name = "longitude", value = "经度", dataType = "string")
    private String longitude;
    @ApiModelProperty(name = "latitude", value = "纬度", dataType = "string")
    private String latitude;
    @ApiModelProperty(name = "mac", value = "设备Mac", dataType = "string",required = true)
    private String mac;
    @ApiModelProperty(name = "modelId", value = "型号Id", dataType = "string",required = true)
    private String modelId;
    @ApiModelProperty(name = "password", value = "密码", dataType = "string")
    private String password;
    @ApiModelProperty(name = "productKey", value = "产品productKey", dataType = "string",required = true)
    private String productKey;
    @ApiModelProperty(name = "sn", value = "设备SN", dataType = "string")
    private String sn;
    @ApiModelProperty(name = "subDevice", value = "子设备", dataType = "integer")
    private Integer subDevice;
    @ApiModelProperty(name = "terminalId", value = "终端Id", dataType = "integer")
    private Integer terminalId;
    @ApiModelProperty(name = "type", value = "类型", dataType = "string")
    private String type;

    @ApiModelProperty(name = "username", value = "用户名", dataType = "string",required = true)
    private String username;

    @ApiModelProperty(name = "phone", value = "phone", dataType = "string",required = true)
    private String phone;

    /**以下部分 授权调用OpenAPi使用**/
    @ApiModelProperty(name = "token", value = "access Token", dataType = "string",required = true)
    private String token;

    @ApiModelProperty(name = "userId", value = "用户Id", dataType = "string",required = true)
    private String userId;

    @ApiModelProperty(name = "appId", value = "application Id", dataType = "string",required = true)
    private String appId;

    @ApiModelProperty("这个字段不需要传，后台组装")
    private String remark;



    public DeviceInfoWithTokenDto() {}

    public DeviceInfoWithTokenDto(String mac, Boolean isOnline, String token, String userId, String appId) {
        this.mac = mac;
        this.isOnline = isOnline;
        this.token = token;
        this.userId = userId;
        this.appId = appId;
    }

    public Integer getSource() {
        return source;
    }

    public void setSource(Integer source) {
        this.source = source;
    }

    public String getAlias() {
        return alias;
    }

    public void setAlias(String alias) {
        this.alias = alias;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getCityCode() {
        return cityCode;
    }

    public void setCityCode(String cityCode) {
        this.cityCode = cityCode;
    }

    public String getDataOne() {
        return dataOne;
    }

    public void setDataOne(String dataOne) {
        this.dataOne = dataOne;
    }

    public String getDataTwo() {
        return dataTwo;
    }

    public void setDataTwo(String dataTwo) {
        this.dataTwo = dataTwo;
    }

    public String getDataThree() {
        return dataThree;
    }

    public void setDataThree(String dataThree) {
        this.dataThree = dataThree;
    }

    public String getDeviceKey() {
        return deviceKey;
    }

    public void setDeviceKey(String deviceKey) {
        this.deviceKey = deviceKey;
    }

    public String getDeviceLock() {
        return deviceLock;
    }

    public void setDeviceLock(String deviceLock) {
        this.deviceLock = deviceLock;
    }

    public String getDid() {
        return did;
    }

    public void setDid(String did) {
        this.did = did;
    }

    public Boolean getOnline() {
        return isOnline;
    }

    public void setOnline(Boolean online) {
        isOnline = online;
    }

    public String getLongitude() {
        return longitude;
    }

    public void setLongitude(String longitude) {
        this.longitude = longitude;
    }

    public String getLatitude() {
        return latitude;
    }

    public void setLatitude(String latitude) {
        this.latitude = latitude;
    }

    public String getMac() {
        return mac;
    }

    public void setMac(String mac) {
        this.mac = mac;
    }

    public String getModelId() {
        return modelId;
    }

    public void setModelId(String modelId) {
        this.modelId = modelId;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getProductKey() {
        return productKey;
    }

    public void setProductKey(String productKey) {
        this.productKey = productKey;
    }

    public String getSn() {
        return sn;
    }

    public void setSn(String sn) {
        this.sn = sn;
    }

    public Integer getSubDevice() {
        return subDevice;
    }

    public void setSubDevice(Integer subDevice) {
        this.subDevice = subDevice;
    }

    public Integer getTerminalId() {
        return terminalId;
    }

    public void setTerminalId(Integer terminalId) {
        this.terminalId = terminalId;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getAppId() {
        return appId;
    }

    public void setAppId(String appId) {
        this.appId = appId;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    /**
     * 校验关键参数
     * @return
     */
    public String valid(){
        //验证公共参数
        if(token == null){
            return "token is null";
        }

        if(appId == null){
            return "appId is null";
        }

        if(userId == null){
            return "userId is null";
        }

        if(source==null){
            return "source is null";
        }

        if(mac == null){
            return "mac is null";
        }

        if(mac.length()>64){
            return "mac max length is 64";
        }

        if(alias!=null && alias.length()>200){
            return "alias max length is 200";
        }

        if(password!=null && password.length()>255){
            return "Password max length is 255";
        }

        if(city!=null && city.length()>20){
            return "city max length is 20";
        }

        if(cityCode!=null && cityCode.length()>20){
            return "cityCode max length is 20";
        }

        if(sn!=null && sn.length()>64){
            return "Sn max length is 64";
        }

        if(longitude!=null && longitude.length()>10){
            return "longitude max length is 10";
        }

        if(latitude!=null && latitude.length()>10){
            return "latitude max length is 10";
        }

        if(modelId == null){
            return "modelId is null";
        }

        if(modelId.length() > 36){
            return "modelId max length is 36";
        }

        if(isOnline == null){
            return "isOnline is null";
        }


        if(source == 0){
            //古北
            if(type!=null && type.length()>255){
                return "type max length is 255";
            }

            if(deviceKey!=null && deviceKey.length()>100){
                return "deviceKey max length is 100";
            }

            if(deviceLock!=null && deviceLock.length()>100){
                return "deviceLock max length is 100";
            }

            if(dataOne!=null && dataOne.length()>30){
                return "dataOne max length is 30";
            }

            if(dataTwo!=null && dataTwo.length()>30){
                return "dataTwo max length is 30";
            }

            if(dataThree!=null && dataThree.length()>30){
                return "dataThree max length is 30";
            }


        }else if(source == 1) {
            //机智云
            if(productKey!=null && productKey.length()>36){
                return "productKey max length is 36";
            }

            if(did!=null && did.length()>100){
                return "did max length is 36";
            }

        }else {
            return "source非法：source ：0 古北云，1 机智云";
        }

        return null;
    }

    public Boolean needSaveToPaas(){
        return  did != null && productKey != null;
    }
}
